package com.base;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.base.entity.OmOrganizationMember;

public class SortListBeanCnForEn {
	public void sortOomList(List<OmOrganizationMember> orgList) {
        Collections.sort(orgList, new Comparator<OmOrganizationMember>() {
            @Override
            public int compare(OmOrganizationMember m1, OmOrganizationMember m2) {
                char c1 = m1.getMemberName().charAt(0);
                char c2 = m2.getMemberName().charAt(0);

                return concatPinyinStringArray(net.sourceforge.pinyin4j.PinyinHelper.toHanyuPinyinStringArray(c1))
                        .compareTo(
                                concatPinyinStringArray(net.sourceforge.pinyin4j.PinyinHelper
                                        .toHanyuPinyinStringArray(c2)));
            }
        });
    }

    private String concatPinyinStringArray(String[] pinyinArray) {
        StringBuffer pinyinSbf = new StringBuffer();
        if ((pinyinArray != null) && (pinyinArray.length > 0)) {
            for (int i = 0; i < pinyinArray.length; i++) {
                pinyinSbf.append(pinyinArray[i]);
            }
        }
        return pinyinSbf.toString();
    }
}
